package classwork.demo1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcDemo3 {
    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //连接数据库
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db2", "root", "root");
        //获取数据库对象
        Statement st = connection.createStatement();
        //数据库对象执行sql语句 读取
        ResultSet rs= st.executeQuery("select * from stu");
        //循环判断读取到控制台
        while (rs.next()){
            System.out.println(rs.getInt("id")+"\t"+rs.getString("name")+"\t"+rs.getString("password"));
        }
    }
}
